package com.demo.quartz;

import org.quartz.*;

import java.util.Calendar;

public class MyJob implements Job {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println("job start");

        Scheduler scheduler = jobExecutionContext.getScheduler();
        Calendar now = Calendar.getInstance();

        System.out.println(now.getTime());
//        try {
//            List<JobExecutionContext> currentlyExecutingJobs = scheduler.getCurrentlyExecutingJobs();
//            for (JobExecutionContext jobContext: currentlyExecutingJobs)
//            {
//                /**
//                 * 当前job执行时间
//                 */
//                Date fireTime = jobContext.getFireTime();
//                System.out.println("----------------- fireTime = "+fireTime);
//                /**
//                 * 前一个job 执行时间
//                 */
//                Date previousFireTime = jobContext.getPreviousFireTime();
//                System.out.println("***************** previousFireTime = "+previousFireTime);
//                Trigger trigger = jobContext.getTrigger();
//                Scheduler scheduler1 = jobContext.getScheduler();
//                Trigger.TriggerState triggerState = scheduler1.getTriggerState(trigger.getKey());
//
//                System.out.println("######## job status is "+triggerState);
//            }
//
//        } catch (SchedulerException e) {
//            e.printStackTrace();
//        }
    }
}
